package com.yxh.www.crawler.client;

import com.xuxueli.crawler.XxlCrawler;
import com.xuxueli.crawler.proxy.ProxyMaker;
import com.xuxueli.crawler.proxy.strategy.RandomProxyMaker;
import com.xuxueli.crawler.proxy.strategy.RoundProxyMaker;
import com.yxh.www.crawler.parser.ZmProxyIpParser;
import com.yxh.www.crawler.util.CrawlerBuilder;

/**
 * <p>
 *  抓取代理IP列表客户端
 * </p>
 *
 * @author yangxiaohui
 * @since 2020/5/15
 */
public class ZmProxyIpCrawlerClient {
    /**
     * 随机选择代理的 代理池
     */
    private ProxyMaker randomProxyMaker;
    /**
     * 循环选择代理的 代理池
     */
    private ProxyMaker roundProxyMaker;

    public ZmProxyIpCrawlerClient(){
        this.reloadProxyMaker();
    }

    /**
     * 刷新代理池
     */
    public ZmProxyIpCrawlerClient reloadProxyMaker(){
        ZmProxyIpParser zmProxyIpParser=new ZmProxyIpParser();
        CrawlerBuilder.builder()
                .setUrls("http://http.tiqu.alicdns.com/getip3?num=1&type=1&pro=&city=0&yys=0&port=1&pack=98562&ts=0&ys=0&cs=0&lb=6&sb=,&pb=4&mr=1&regions=&gm=4")
                .start(zmProxyIpParser).stop();
        this.randomProxyMaker=zmProxyIpParser.getRandomProxyMaker();
        this.roundProxyMaker=zmProxyIpParser.getRoundProxyMaker();
        return this;
    }

    public ProxyMaker getRandomProxyMaker() {
        return randomProxyMaker;
    }

    public ProxyMaker getRoundProxyMaker() {
        return roundProxyMaker;
    }
}
